﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate.Cfg;
using NHibernate.Mapping;

namespace NHibernate.Audit.Mapping
{
    public class MappingsFacade : IMappingsFacade
    {

        public MappingsFacade(Configuration configuration)
        {
            var props = configuration.Properties;
            dialect = NHibernate.Dialect.Dialect.GetDialect(props);
            mappings = configuration.CreateMappings(dialect);
        }

        public MappingsFacade(Mappings mappings, NHibernate.Dialect.Dialect dialect)
        {
            this.mappings = mappings;
            this.dialect = dialect;
        }

        private Mappings mappings;
        private NHibernate.Dialect.Dialect dialect;

        #region IMappingsFacade Members

        public void CreatePrimaryKeyFor(PersistentClass clazz)
        {
            clazz.CreatePrimaryKey(dialect);
        }

        public void AddClass(PersistentClass clazz)
        {
            mappings.AddClass(clazz);
        }

        #endregion

        #region ITableFactory Members

        public Table CreateTable(string Catalog, string Schema, string Name, bool IsAbstract)
        {
            return mappings.AddTable(Schema, Catalog, Name, null, IsAbstract, null);
        }

        #endregion
    }
}
